﻿using System;
using Csla;
using SystemX.Infrastructure;

namespace SystemX.Csla
{
    /// <summary>
    /// Extension business base class.
    /// </summary>
    /// <typeparam name="TId">Id type</typeparam>
    /// <typeparam name="T">Business object Type</typeparam>
    [Serializable]
    public abstract class XBusinessBase<T> : BusinessBase<T>
        where T : XBusinessBase<T>
    {

        #region .ctor
        protected XBusinessBase() { }
        #endregion

        #region Member variables
        #endregion

        #region Methods
        /// <summary>
        /// Ensures that the specified dependency exists (is not null).
        /// </summary>
        /// <typeparam name="TDependency">
        /// The type of the dependency.
        /// </typeparam>
        /// <param name="dependency">
        /// The dependency instance.
        /// </param>
        /// <returns>
        /// The same <paramref name="dependency"/> instance that was passed to the method.
        /// </returns>
        /// <exception cref="MissingDependencyInjectionException">
        /// When <paramref name="dependency"/> is null.
        /// </exception>
        protected TDependency EnsureDependency<TDependency>(TDependency dependency) where TDependency : class
        {
            if (dependency == null)
                throw new MissingDIException(this.GetType(), typeof(TDependency));
            return dependency;
        }
        #endregion
    }
}
